package org.elucid.gadmin.ui.events;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;

import org.elucid.gadmin.Utilities;
import org.elucid.gadmin.ui.GDialog;

/**
 * 
 * @author george
 *
 */
public class OpenActionListener implements ActionListener {

	GDialog gDialog;

	public OpenActionListener(GDialog gDialog) {
		super();
		this.gDialog = gDialog;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		final JFileChooser fc = new JFileChooser();
		int returnVal = fc.showOpenDialog(gDialog);
		if (returnVal == 0) {
			gDialog.setFile(fc.getSelectedFile());
			try {
				gDialog.setTitle(gDialog.getFile().getName());
				gDialog.getTextPane().setText(Utilities.readTextFile(gDialog.getFile()));
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

	}
}
